feat(voice): add session-scoped mockTools for testing#1980
Open
toubatbrian wants to merge 2 commits into
Open
Conversation
Ports the session form of mock_tools from livekit/agents#6080: mockTools(AgentType, mocks, session) assigns a mock set for an Agent type on a specific session, effective immediately and for the session's lifetime. Re-registering replaces the set; an empty record removes it. Context-scoped withMockTools mocks take precedence when both are active. Unlike the Python original (where the session store is currently written but never consulted), getMockTool resolves session mocks during tool execution. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 9d04644 The changes in this PR will be included in the next version bump. This PR includes changesets to release 36 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A context-scoped mock set for one tool no longer disables session-scoped mocks for the agent's other tools: a scope whose set lacks the tool falls through to the next scope instead of unmocking it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1978, porting the half of livekit/agents#6080 that PR skipped: the session-scoped
mock_toolsAPI.mockTools(AgentType, mocks, session)tovoice.testing: assigns the mock set for an Agent type on a specific session, effective immediately and for the session's lifetime (stored in aWeakMapkeyed by session, so it never outlives it)getMockToolnow also consults session-scoped mocks during tool execution, with context-scopedwithMockToolsmocks taking precedence — matching the precedence documented in the Python originalNote on the Python original
In current Python upstream,
_SessionMockToolsis written bymock_tools(..., session=session)but never read —generation.pyonly consults the context-var mocks, so the session form appears to be a no-op there. This port wires up the read side (getMockTool→performToolExecutions), which is the documented intent of the upstream API. Filing this discrepancy upstream separately.Testing
pnpm vitest run agents/src/voice/testing/run_result.test.ts— 11 tests pass, including 5 new ones: session registry resolution, per-session isolation, replace/remove semantics, context-over-session precedence, and end-to-end routing throughperformToolExecutionspnpm vitest run agents/src/voice/— no regressions (only the pre-existingamd.test.tsfailures, which fail identically onmain)pnpm build:agents, Prettier cleanPorted from livekit/agents#6080